
// import oimo.common.Setting;
// import oimo.common.Vec3;
// import oimo.dynamics.rigidbody.*;

import { RigidBody } from "../../rigidbody/RigidBody";
import { Vec3 } from "../../../common/Vec3";
import { Setting } from "../../../common/Setting";

/**
 * A joint configuration is used for constructions of various joints.
 * An instance of any kind of the joint configurations can safely be reused.
 */
export class JointConfig {
	/**
	 * The first rigid body attached to the joint.
	 */
	rigidBody1: RigidBody;

	/**
	 * The second rigid body attached to the joint.
	 */
	rigidBody2: RigidBody;

	/**
	 * The local position of the first rigid body's anchor point.
	 */
	localAnchor1: Vec3;

	/**
	 * The local position of the second rigid body's anchor point.
	 */
	localAnchor2: Vec3;

	/**
	 * Whether to allow the connected rigid bodies to collide each other.
	 */
	allowCollision: boolean;

	/**
	 * The type of the constraint solver for the joint.
	 *
	 * See `ConstraintSolverType` for details.
	 */
	solverType: number;

	/**
	 * The type of the position correction algorithm for the joint.
	 *
	 * See `PositionCorrectionAlgorithm` for details.
	 */
	positionCorrectionAlgorithm: number;

	/**
	 * The joint will be destroyed when magnitude of the constraint force exceeds the value.
	 *
	 * Set `0` for unbreakable joints.
	 */
	breakForce: number;

	/**
	 * The joint will be destroyed when magnitude of the constraint torque exceeds the value.
	 *
	 * Set `0` for unbreakable joints.
	 */
	breakTorque: number;


	constructor() {
		this.rigidBody1 = null;
		this.rigidBody2 = null;
		this.localAnchor1 = new Vec3();
		this.localAnchor2 = new Vec3();
		this.allowCollision = false;
		this.solverType = Setting.defaultJointConstraintSolverType;
		this.positionCorrectionAlgorithm = Setting.defaultJointPositionCorrectionAlgorithm;
		this.breakForce = 0;
		this.breakTorque = 0;
	}

	// --- ---

	public _init(rb1: RigidBody, rb2: RigidBody, worldAnchor: Vec3): void {
		this.rigidBody1 = rb1;
		this.rigidBody2 = rb2;
		this.rigidBody1.getLocalPointTo(worldAnchor, this.localAnchor1);
		this.rigidBody2.getLocalPointTo(worldAnchor, this.localAnchor2);
	}

}
